home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / c / qtools0.2-src.lha / src / util / minimalistic / lightLIGHT.c next >
Encoding:
C/C++ Source or Header  |  1998-07-08  |  1.9 KB  |  78 lines

  1. #include "qtools.h"
  2.  
  3. struct memory bspStatic;
  4. struct memory *bspMem = &bspStatic;
  5.  
  6.  
  7. /*
  8.  * ========
  9.  * main
  10.  * 
  11.  * light modelfile
  12.  * ========
  13.  */
  14. int main(int argc, char **argv)
  15. {
  16.   int i;
  17.   char source[NAMELEN_PATH];
  18.   FILE *bspFile;
  19.   float scaledist = 0, rangescale = 0;
  20.  
  21.   memset(bspMem, 0, sizeof(struct memory));
  22.   if (!setjmp(eabort)) {
  23.     printf("----- LightFaces --------\n");
  24.  
  25.     for (i = 1; i < argc; i++) {
  26.       if (!strcmp(argv[i], "-extra")) {
  27.         bspMem->litOptions |= LIGHT_EXTRA;
  28.         mprintf("extra sampling enabled\n");
  29.       }
  30.       else if (!strcmp(argv[i], "-rad")) {
  31.         bspMem->litOptions |= LIGHT_RADIOSITY;
  32.         mprintf("radiosity calculation enabled\n");
  33.       }
  34.       else if (!strcmp(argv[i], "-waterlit")) {
  35.         bspMem->litOptions |= LIGHT_WATERLIT;
  36.         mprintf("extra watershadowing enabled\n");
  37.       }
  38.       else if (!strcmp(argv[i], "-dist")) {
  39.         scaledist = atof(argv[i + 1]);
  40.         i++;
  41.       }
  42.       else if (!strcmp(argv[i], "-range")) {
  43.         rangescale = atof(argv[i + 1]);
  44.         i++;
  45.       }
  46.       else if (argv[i][0] == '-')
  47.         Error("Unknown option \"%s\"", argv[i]);
  48.       else
  49.         break;
  50.     }
  51.  
  52.     if (i != argc - 1)
  53.       Error("usage: light [-extra] bspfile");
  54.  
  55.     strcpy(source, argv[i]);
  56.     ReplaceExt(source, "bsp");
  57.     if((bspFile = fopen(source, READWRITE_BINARY_OLD))) {
  58.       if((bspMem = LoadBSP(bspFile, ALL_QUAKE1_LUMPS & (~(LUMP_LIGHTING | LUMP_VISIBILITY)), BSP_VERSION_Q1))) {
  59.         if(light(bspMem, scaledist, rangescale) == FALSE)
  60.           eprintf("failed to calculate light-lump\n");
  61.         else        
  62.           WriteBSP(bspFile, bspMem);
  63.  
  64.         PrintClusters(bspMem, LUMP_LIGHTING, TRUE);
  65.         FreeClusters(bspMem, 0);
  66.       }
  67.       else
  68.         eprintf("failed to open bspfile %s\n", source);
  69.       
  70.       fclose(bspFile);
  71.     }
  72.     else
  73.       eprintf("failed to open bspfile %s\n", source);
  74.   }
  75.  
  76.   return 0;
  77. }
  78.